package utils

import com.jfinal.upload.UploadFile
import java.io.File

object ResUtils{

    fun saveGoodsPic(file: UploadFile, fileName: String): String?{
        val newPath = file.uploadPath + "/pictures/goods/$fileName"
        val tmp = File(newPath)
        if (tmp.exists() || file.file.renameTo(tmp)){
            file.file.delete()
            return "/res/goods/$fileName"
        }
        return null
    }

    fun getGoodsPicLocalFile(file: UploadFile): File{
        return File("${file.uploadPath}/pictures/goods/${file.fileName}")
    }

    fun saveAvatar(file: UploadFile, fileName: String): String? {
        val newPath = file.uploadPath + "/pictures/goods/$fileName"
        val tmp = File(newPath)
        if (tmp.exists() || file.file.renameTo(tmp)){
            file.file.delete()
            return "/res/avatars/$fileName"
        }
        return null
    }

}